﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using NTQOnlineExam.Services.DBCommand;
using NTQOnlineExam.Services.Infrastructure.Utility;

namespace NTQOnlineExam.Services.CommandService.Answer
{
    public class AnswerCommandService : IAnswerCommandService
    {
        public bool CreateAnswer(int questionId, string content, out int answerId)
        {
            Guard.Against<ArgumentException>(questionId <= 0, "QuestionId Id is required");
            Guard.Against<ArgumentException>(String.IsNullOrWhiteSpace(content), "Answer content can not be null or empty!");
            var result = DBCommand.DBCommand.CreateInstant().CreateAnswerDbCommand(questionId, content, out answerId);
            return result;
        }

        public bool UpdateAnswer(UpdateAnswerCommand updateAnswerCommand)
        {
            Guard.Against<ArgumentException>(updateAnswerCommand.QuestionId <= 0, "QuestionId Id is required");
            Guard.Against<ArgumentException>(String.IsNullOrWhiteSpace(updateAnswerCommand.Content), "Answer content can not be null or empty!");
            var result = DBCommand.DBCommand.CreateInstant().UpdateAnswerDbCommand(updateAnswerCommand);
            return result;
        }

        public bool DeleteAnswer(int answerId)
        {
            Guard.Against<ArgumentException>(answerId <= 0, "AnswerId Id is required");
            var result = DBCommand.DBCommand.CreateInstant().DeleteAnswerDbCommand(answerId);
            return result;
        }

    }
}
